package com.kzd.gtgame.main.popup

import android.content.Context
import android.text.Editable
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import android.widget.*
import androidx.core.widget.addTextChangedListener
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.kzd.gtgame.R
import com.kzd.gtgame.custom.setOnClickAntiShakeListener
import com.kzd.gtgame.entity.WelfareCoupon
import com.kzd.gtgame.main.home.adapter.CouponPriceAdapter
import razerdp.basepopup.BasePopupWindow


class CouponReplyPopup(
    context: Context, val onClick: (view: View, content: String) -> Unit
) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.BOTTOM
        setOverlayNavigationBar(false)
    }

    private var etDiscussReplyContent: EditText? = null

    private var tvDiscussReplySubmit: TextView? = null

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_discuss_reply)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        etDiscussReplyContent = contentView.findViewById(R.id.etDiscussReplyContent)
        tvDiscussReplySubmit = contentView.findViewById(R.id.tvDiscussReplySubmit)
        etDiscussReplyContent?.addTextChangedListener {
            tvDiscussReplySubmit?.isEnabled = !it.isNullOrEmpty()
        }
        tvDiscussReplySubmit?.setOnClickAntiShakeListener {
            onClick(it, etDiscussReplyContent?.text.toString())
        }
    }

    override fun onCreateShowAnimation(width: Int, height: Int): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f,
            Animation.RELATIVE_TO_PARENT, 0f
        ).apply { duration = 300L }
    }

    override fun onCreateDismissAnimation(): Animation {
        return TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 0f,
            Animation.RELATIVE_TO_PARENT, 1f
        ).apply { duration = 300L }
    }

    fun fillData(): CouponReplyPopup {
        etDiscussReplyContent?.text = null
        return this
    }

}